<?php defined('SEJUJOPEFDNGJSL') or exit('Access denied');?>
<?php
    $rr=$config->getpwd();
 //    $db->query("select * from ld_address where adid=".$_userid."",2);
	// $dl=$db->rs;
	// if(empty($dl)){
	// 	 msg_l("您还没有填收款地址，请先填写!",$backurl."/home.php?lsact=myaddress");
	// }
?>
<?php require("topbut.php");
?>
	<div class="panel panel-inverse">
        <div class="panel-heading">
            <h4 class="panel-title">锁仓生息</h4>
        </div>
        <div class="panel-body">
        	<form action="" method="post" name="theform" class="form-horizontal">
        		<script type="text/javascript">
				</script>
        		<fieldset style="border: none;">

					<div id="amountsel">

            <div class="form-group">
                <label class="col-md-3 control-label ui-sortable">套餐</label>
                <input type="hidden" name="tctype" id="tctype" value="" />
                <div class="col-md-9 ui-sortable" id="ddtype">
                    <div class="setamount"><input type="button" onclick="setamount('A',1);this.setAttribute('style','color:#9bd130;font-weight:bold;background:#fff;border:1px solid #9bd130;');" value="A套餐" class="sa800" style="background: #9bd130;" /></div>
                    <div class="setamount"><input type="button" onclick="setamount('B',2);this.setAttribute('style','color:#efb544;font-weight:bold;background:#fff;border:1px solid #efb544;');" value="B套餐" class="sa1000" style="background: #efb544;" /></div>
                    <div class="setamount"><input type="button" onclick="setamount('C',3);this.setAttribute('style','color:#ad3446;font-weight:bold;background:#fff;border:1px solid #ad3446;');" value="C套餐" class="sa1000"  style="background: #ad3446;"/></div>
                    <div class="setamount"><input type="button" onclick="setamount('D',4);this.setAttribute('style','color:#5eb36c;font-weight:bold;background:#fff;border:1px solid #5eb36c;');" value="D套餐" class="sa1000"  style="background: #5eb36c;"/></div>
                    <div class="setamount"><input type="button" onclick="setamount('E',5);this.setAttribute('style','color:#3cadb7;font-weight:bold;background:#fff;border:1px solid #3cadb7;');" value="E套餐" class="sa1000"  style="background: #3cadb7;"/></div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label ui-sortable">套餐详情</label>
                <div class="col-md-9 ui-sortable" id = 'guize' style='color: red;'>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label ui-sortable">锁仓方式</label>
                <div class="col-md-9 ui-sortable">
                  <select class="form-control"  name="xf_type" id="xf_type">
                      <option value="0">请选择锁仓方式</option>
                      <option value="1">VIC</option>
                      <option value="2">锁仓收益</option>
                      <option value="3">团队收益</option>
                  </select>
                </div>
            </div>
            <div class="form-group xfje">
  						<label class="col-md-3 control-label ui-sortable">锁仓数量</label>
              <div class="col-md-9 ui-sortable">
  						  <input type="text" name="jine" id="jine" value="" class="form-control" />
              </div>
            </div>
            <div class="form-group shop" style="display:none">
              <div class="col-md-9 col-md-offset-3 ui-sortable">
                <input type="button" onclick="choose()" value="选择商品" class="shangpinbut btn btn-md btn-success"/>
              </div>
            </div>
					</div>
            <div class="form-group">
                <label class="col-md-3 control-label ui-sortable">交易密码</label>
                <div class="col-md-9 ui-sortable">
                 <input type="password" name="pwd" id="pwd" class="form-control" required="required" autocomplete="off" />
                </div>
            </div>
            <div class="form-group">
              <div class="col-md-9 col-md-offset-3 ui-sortable">
                <input type="button" onclick="check()" class="btn btn-md btn-primary" value="确定">
              </div>
            </div>
        </fieldset>
			</form>

        </div>
    </div>

<script type="text/javascript" src="/public/home/js/layer/layer.js"></script>
<script type="text/javascript">
$('#jine').css("ime-mode","disabled").bind('keyup change',function(){
  var amount = $('#jine').val();
  if(amount.indexOf(".") != "-1"){
    var barr = amount.split(".");
    var xiaoshu = barr[1].length;
    if(xiaoshu>4){
      var org = barr[1].substr(0,xiaoshu-1);
      var xin = parseFloat(barr[0]+"."+org);
      $("#jine").val(xin);
    }
  }


});

function setamount(val,id){
	var arr = document.getElementById("ddtype").getElementsByTagName("input");
	for(var i=0;i<arr.length;i++){
		arr[i].setAttribute("style","color:white;font-weight:normal;");
    arr[0].setAttribute("style","background-color:#9bd130;");
    arr[1].setAttribute("style","background-color:#efb544;");
    arr[2].setAttribute("style","background-color:#ad3446;");
    arr[3].setAttribute("style","background-color:#5eb36c;");
    arr[4].setAttribute("style","background-color:#3cadb7;");
	}
	if(val){
		document.getElementById("tctype").value=val;
    $.post("/ajax.php?act=get_meal",{id:id},function(data){
      localStorage.setItem('data_meal', JSON.stringify(data));
      //{"id":"4","title":"D\u5957\u9910","min":"5000","max":"9999","days":"120","meal":"0.0800","type":"1"}
      $('#guize').empty();
      $('#guize').html(data.title+' ==> '+data.min+' -- '+data.max+';锁仓时间：'+data.days+'天；每日收益：'+data.meal+';');

    },'json');
	}else{
		alert('请选择一个套餐！');
	}
}
$('#xf_type').change(function(){
	  var type=$('#xf_type').find("option:selected").val();
	  // if(type==1){
	  // 	$('.shop').css('display','block');
   //    $('.xfje').css('display','none');
	  // }else{
	  // 	$('.shop').css('display','none');
   //    $('.xfje').css('display','block');
	  // }
})



</script>


<script>
function check(){
      var type=$('#xf_type').find("option:selected").val();
      var jine=$('#jine').val();
      var tctype=$('#tctype').val();
      var pwd=$('#pwd').val();
      var data_meal = JSON.parse(localStorage.getItem('data_meal'));
      if(tctype=='' || !data_meal){
        layer.alert("请选择套餐！");
         return;
      }
      if(type<1){
         layer.alert("请选择锁仓方式！");
         return;
      }
      if(jine==''){
        layer.alert("请选择锁仓金额！");
         return;
      }
      if(pwd==''){
        layer.alert("请输入密码！");
        return;
      }
      if(!(parseInt(data_meal.min) <= parseInt(jine) && parseInt(jine)<= parseInt(data_meal.max))){
        layer.alert('输入的数量与套餐不匹配！');
        return ;
      }
      if(jine<20){
        layer.alert("锁仓额度不得小于20！");
         return;
      }
      var ids='';
      var nums='';

      var index = layer.load(0, {shade: [0.5,'#8F8F8F']});
      var ajaxTimeoutTest =$.ajax({
      type: "get",
      dataType: "json",
      timeout : 13000,
      url: "/ajax.php?act=cunqian&jine="+jine+"&pwd="+pwd+"&xf_type="+type+"&tctype="+tctype+"&dataid="+data_meal.id,
      success: function(data){
        //console.log("/ajax.php?act=cunqian&jine="+jine+"&pwd="+pwd+"&xf_type="+type+"&tctype="+tctype);
        if(data.status==0){
          layer.alert(data.tips, function(index){
              layer.closeAll();
          });

        }else{
          layer.alert(data.tips, function(index){
              window.location.href="home.php?lsact=index";
          });

        }
      },
      error: function(){

      },
      complete : function(XMLHttpRequest,status){ //请求完成后最终执行参数
　　　　　       if(status=='timeout'){//超时,status还有success,error等值的情况
 　　　　　      ajaxTimeoutTest.abort();
        layer.alert('现在人多请稍后重试，不要刷新页面，请重新提交！', function(index){
              layer.closeAll();
          });

　　　　     }
　　　　　 }
      });
  }

</script>
<script type="text/javascript">

function jian(id){
  var nums = $('#num'+id).val();
    if(!nums){ nums = 0;}
    nums = parseFloat(nums) - 1;
    if(nums <= 0){ nums = 1}
    $('#num'+id).val(nums);
  var good_tot=0;
  $('input[name="goods"]:checked').each(function(){

          gid=$(this).val();
          var price=parseInt($("#goodid"+gid).val());
          var num=parseInt($("#num"+gid).val());
          tot=price*num;
          good_tot=good_tot+tot;

  });
  $('#heji').html(good_tot);
}
function jia(id){
  var nums = $('#num'+id).val();
            if(!nums){ nums = 0;}
            nums = parseFloat(nums) + 1;
            $('#num'+id).val(nums);
  var good_tot=0;
  $('input[name="goods"]:checked').each(function(){

            gid=$(this).val();
            var price=parseInt($("#goodid"+gid).val());
            var num=parseInt($("#num"+gid).val());
            tot=price*num;
            good_tot=good_tot+tot;

  });
  $('#heji').html(good_tot);
}

function heji(){
  var good_tot=0;
  $('input[name="goods"]:checked').each(function(){
          gid=$(this).val();
          var price=parseInt($("#goodid"+gid).val());
          var num=parseInt($("#num"+gid).val());
          tot=price*num;
          good_tot=good_tot+tot;

  });
  $('#heji').html(good_tot);
}


</script>

